<?php

namespace App\Containers\AppSection\Data\Data\Repositories;

use App\Containers\AppSection\Data\Models\Personal;
use App\Ship\Parents\Repositories\Repository;

class PersonalRepository extends Repository
{
    /**
     * @var array
     */
    protected $fieldSearchable = [
        'id' => '=',
        // ...
    ];

    public function check(int $id, string $legalForm, $roleName): bool
    {
        /** @var Personal $entity */
        $entity = $this->find($id);

        if ($legalForm === 'ie' && empty($entity->ogrnip))
            return true;

        if ($roleName === 'borrower' && empty($entity->snils))
            return true;

        if ($roleName === 'borrower' && empty($entity->residence_address))
            return true;

        if ($legalForm === 'entity' && empty($entity->position))
            return true;

        return empty($entity->fio) ||
            empty($entity->birth_date) ||
            empty($entity->inn) ||
            empty($entity->birth_place) ||
            empty($entity->registration_address);
    }
}
